package stack_queue.oj;

import java.util.Stack;

public class Num901 {
    Stack<Integer> prices;
    Stack<Integer> weights;

    public Num901() {
        prices = new Stack();
        weights = new Stack();
    }

    public int next(int price) {
        int w = 1;
        while (!prices.isEmpty() && prices.peek() <= price) {
            prices.pop();
            w += weights.pop();
        }

        prices.push(price);
        weights.push(w);
        return w;
    }

    public static void main(String[] args) {
        Num901 S = new Num901();
        S.next(100);
        System.out.println(S.weights.peek());
        S.next(80);
        System.out.println(S.weights.peek());
        S.next(60);
        System.out.println(S.weights.peek());
        S.next(70) ;
        System.out.println(S.weights.peek());
        S.next(60) ;
        System.out.println(S.weights.peek());
        S.next(75) ;
        System.out.println(S.weights.peek());
        S.next(85) ;
        System.out.println(S.weights.peek());
    }
}
